package com.gmail.ceac13;


import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class ConfiguracoesActivity extends Activity {

	private static final String[] minutos = {"1 min","5 min","10 min", "30 min", "60 min"};
	
	private static final String[] metros = {"10 m","100 m","500 m", "1 km", "5 km", "10 km", "50 km"};
	
		
	ArrayAdapter<String> aMinutos;
	
	ArrayAdapter<String> aMetros;
	
	Spinner spnMin;
	
	Spinner spnMet;
	
	EditText endereco;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		 super.onCreate(savedInstanceState);
		
		 setContentView(R.layout.configuracao);
		
		aMinutos = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, minutos);
		
		aMetros = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, metros);
        
		
		spnMin = (Spinner) findViewById(R.id.spiMin);
        spnMin.setAdapter(aMinutos);
        
        spnMet = (Spinner) findViewById(R.id.spiMet);
        spnMet.setAdapter(aMetros);
        endereco = (EditText) findViewById(R.id.enderecoServidor);
        
        
           
        final SharedPreferences settings = getSharedPreferences("ConnectMe",MODE_PRIVATE);
        
        int temp = settings.getInt("tempo", 0);
        int dist = settings.getInt("distancia", 6);
        String end = settings.getString("servidor", "http://connectme.scienceontheweb.net/");
        //String end = settings.getString("servidor", "http://10.0.2.2/connectme/");
        
        
        spnMin.setSelection(temp);
        spnMet.setSelection(dist);
        endereco.setText(end);
        
        Button btMens = (Button) findViewById(R.id.btnSave);
        
        btMens.setOnClickListener(new View.OnClickListener() {
    		
        	public void onClick(View arg0) {
        		SharedPreferences.Editor editor = settings.edit();
        		editor.putInt("tempo", spnMin.getSelectedItemPosition());
        		editor.putInt("distancia", spnMet.getSelectedItemPosition());
        		editor.putString("servidor", endereco.getText().toString());
                editor.commit();
                
        		finish();
    	
        	}
        });
		
	}
	
}
